﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;

namespace NetOrientDB.ObjectModel
{
	public class OrientClass
	{
		public int Id { get; set; }
		public string Name { get; set; }
		public int[] Clusters { get; set; }
		public int DefaultCluster { get; set; }
		public long Records { get; set; }
		public List<OrientProperty> Properties { get; set; }

		public OrientClass()
		{
		}
		public OrientClass(JObject jObj)
		{
			this.Parse(jObj);
		}

		public void Parse(JObject jObj)
		{
			this.Id = jObj.Value<int>("id");
			this.Name = jObj.Value<string>("name");
			this.DefaultCluster = jObj.Value<int>("defaultCluster");
			this.Records = jObj.Value<long>("records");
			var clusters = jObj.Value<JArray>("clusters");
			this.Clusters = clusters.Values<int>().ToArray();
			this.Properties = new List<OrientProperty>();
			var jprops = jObj.Value<JArray>("properties");
			if (jprops != null)
			{
				foreach (JObject jprop in jprops)
				{
					var p = new OrientProperty(jprop);
					this.Properties.Add(p);
				}
			}
		}
		public override string ToString()
		{
			return this.Name;
		}
	}
}
